package com.cyw.search.service.impl;

import cn.easyes.core.conditions.LambdaEsQueryWrapper;
import com.cyw.common.helper.LoginHelper;
import com.cyw.search.entity.monents.Moments;
import com.cyw.search.entity.videos.Videos;
import com.cyw.search.mapper.EsUserMapper;
import com.cyw.search.mapper.MomentsMapper;
import com.cyw.search.mapper.SearchNoteEntityMapper;
import com.cyw.search.mapper.VideosMapper;
import com.cyw.search.service.UpdateUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: 二叔
 * @Date: 2022/11/24/19:50
 */
@Service
public class UpdateUserImpl implements UpdateUser {

    @Resource
    private SearchNoteEntityMapper searchNoteEntityMapper;

    @Resource
    private MomentsMapper momentsMapper;

    @Resource
    private VideosMapper videosMapper;

    @Resource
    private EsUserMapper esUserMapper;

    @Override
    public void updateUserAvatar(String avatar) {

//        /***
//         * 用户
//         */
//        EsUser esUser = esUserMapper.selectById(LoginHelper.getUserId());
//        esUser.getSysUser().setAvatar(avatar);
//        esUserMapper.insert(esUser);

        LambdaEsQueryWrapper<Moments> wrapperMoments = new LambdaEsQueryWrapper<>();
        wrapperMoments.eq(Moments::getUserId,LoginHelper.getUserId());
        List<Moments> momentsList = momentsMapper.selectList(wrapperMoments);
        momentsList.forEach(moments -> moments.getCreatorVo().setAvatar(avatar));

        momentsMapper.updateBatchByIds(momentsList);


        LambdaEsQueryWrapper<Videos> wrapperVideos = new LambdaEsQueryWrapper<>();
        wrapperVideos.eq(Videos::getUserId,LoginHelper.getUserId());
        List<Videos> videos = videosMapper.selectList(wrapperVideos);
        videos.forEach(v -> v.getCreatorVo().setAvatar(avatar));

        videosMapper.updateBatchByIds(videos);

    }
}
